package com.jp.knowledge.my.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.my.model.ColleagueAuditModel;
import com.jp.knowledge.util.ImageLoadUtil;
import com.jp.knowledge.util.TimeUtil;

import java.util.List;

public class AuditListAdapter extends RecycleVAdapter<ColleagueAuditModel> implements View.OnClickListener {

    public AuditListAdapter(Context context, @NonNull List<ColleagueAuditModel> list) {
        super(context, list);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_audit_join;
    }

    @Override
    public void onBind(RecycleVHolder holder, final int position) {
        ColleagueAuditModel model = getData(position);
        holder.setTextView(R.id.item_audit_tv_name, model.getUserName());
        holder.setTextView(R.id.item_audit_tv_phone, model.getUserMobile());
        try {
            holder.setTextView(R.id.item_audit_tv_time, TimeUtil.getStandardDate(model.getApplyTime()+""));
        } catch(Exception e){
            holder.setTextView(R.id.item_audit_tv_time, "");
        }

        TextView auditBtn = holder.getTextView(R.id.item_audit_btn);
        auditBtn.setTag(position);
        int status = model.getAuditState();
        if (status== 0){
            auditBtn.setText("审核");
            auditBtn.setBackgroundResource(R.drawable.my_rbtn_blue_press);
            auditBtn.setTextColor(mContext.getResources().getColor(R.color.theme_color));
            auditBtn.setOnClickListener(this);
        }else if(status == 1) {
            auditBtn.setText("已加入");
            auditBtn.setBackgroundResource(R.color.white);
            auditBtn.setTextColor(mContext.getResources().getColor(R.color.theme_color));
        }else {
            auditBtn.setText("已拒绝");
            auditBtn.setBackgroundResource(R.color.white);
            auditBtn.setTextColor(mContext.getResources().getColor(R.color.font_gray));
        }
        ImageLoadUtil.load(mContext,
                model.getUserIcon(),
                holder.getImageView(R.id.item_audit_iv_header),
                R.mipmap.ic_my_header
        );
    }

    private AuditClickListener mListener;

    public void setAuditClickListener(AuditClickListener listener) {
        this.mListener = listener;
    }

    @Override
    public void onClick(View v) {
        if (null == mListener)
            return;
        mListener.onClick((int)v.getTag());
    }

    public interface AuditClickListener {
        void onClick(int position);
    }
}
